from django.contrib.auth.models import User
from django.core.files import base
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.contrib import admin

class FEStudyManager(models.Manager):
    def get_for_user(self, user):
        return self.filter(creator=user).order_by('-creation_date')

class FEStudyModel(models.Model):
    title = models.CharField(max_length=100)
    creator = models.ForeignKey(User)
    creation_date = models.DateTimeField(auto_now_add=True)
    last_modification_date = models.DateTimeField(auto_now=True)
        
    objects = FEStudyManager()
    
    class Meta(object):
        ordering = ["-creation_date"]
        verbose_name = "study"    
        verbose_name_plural = "studies"
        unique_together = ("title", "creator",)

class FEConstraintModel(models.Model):
    unique_id = models.CharField(max_length=100)
    type = models.CharField(max_length=100)
    study = models.ForeignKey(FEStudyModel)
    creation_date = models.DateTimeField(auto_now_add=True)
    last_modification_date = models.DateTimeField(auto_now=True)
        
    objects = FEStudyManager()
    
    class Meta(object):
        ordering = ["-creation_date"]
        verbose_name = "constraint"    
        verbose_name_plural = "constraint"
        unique_together = ("unique_id", "study",)

class FEMaterialModel(models.Model):
    unique_id = models.CharField(max_length=100)
    type = models.CharField(max_length=100)
    study = models.ForeignKey(FEStudyModel)
    creation_date = models.DateTimeField(auto_now_add=True)
    last_modification_date = models.DateTimeField(auto_now=True)
        
    objects = FEStudyManager()
    
    class Meta(object):
        ordering = ["-creation_date"]
        verbose_name = "material"    
        verbose_name_plural = "materials"
        unique_together = ("unique_id", "study",)

class FELoadingModel(models.Model):
    unique_id = models.CharField(max_length=100)
    type = models.CharField(max_length=100)
    study = models.ForeignKey(FEStudyModel)
    creation_date = models.DateTimeField(auto_now_add=True)
    last_modification_date = models.DateTimeField(auto_now=True)
        
    objects = FEStudyManager()
    
    class Meta(object):
        ordering = ["-creation_date"]
        verbose_name = "loading"    
        verbose_name_plural = "loadings"
        unique_together = ("unique_id", "study",)